package com.now.printer.adapter;

import android.app.Activity;
import android.content.Context;
import android.graphics.Rect;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.now.printer.R;
import com.now.printer.base.BaseAdapter.BaseAdapter;
import com.now.printer.base.BaseAdapter.BaseHolder;
import com.now.printer.bean.SearchBean;
import com.scwang.smartrefresh.layout.adapter.BaseRecyclerAdapter;
import com.xuexiang.xaop.annotation.SingleClick;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

/**
 * Created by xudong on 2021/5/16.
 */

public class SearchListAdapter extends BaseAdapter<SearchBean> {
    private OnItemClickListener mOnItemClickListener = null;

    private List<SearchBean> data = new ArrayList<>();

    public void setOnItemClickLitener(OnItemClickListener mOnItemClickListener) {
        this.mOnItemClickListener = mOnItemClickListener;
    }



    public SearchListAdapter(Context context, List<SearchBean> data, int layoutId) {
        super(context, data, layoutId);
        this.data = data;
//        R.layout.item_search_type_list;
    }
    @Override
    public void onBind(BaseHolder holder, SearchBean item, int position) {

        LinearLayout llBox = holder.getView(R.id.llBox);
        TextView itemTypeTxt = holder.getView(R.id.item_typeTxt);
        List<SearchBean> searchBeanList = new ArrayList<>();
        if (item != null) {
            itemTypeTxt.setText( item.getName());
            if (item.isClicks()) {
                llBox.setBackgroundResource(R.drawable.bg_selected);
                itemTypeTxt.setTextColor(R.color.white);
            } else {
                llBox.setBackgroundResource(R.color.picture_transparent);
                itemTypeTxt.setTextColor( R.color.xui_config_color_black);
            }

            llBox.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    searchBeanList.clear();
                    searchBeanList.addAll(getData());
                    for (int i = 0; i < searchBeanList.size(); i++) {
                        searchBeanList.get(i).setClicks(false);
                    }
                    searchBeanList.get(position).setClicks(true);
//                    resetDataSource(searchBeanList);
                    searchBeanList.clear();
                    searchBeanList.addAll(getData());
                    notifyDataSetChanged();
                    if (mOnItemClickListener != null) {
                        mOnItemClickListener.onItemClick(position, item.getName());
                    }
                }
            });
        }
    }

    public interface OnItemClickListener {
        void onItemClick(int position, String type);
    }
}
